<template>
  <el-row type="flex" justify="space-around" align="middle" style="height: 40px;width:100%;">
    <el-col>
      <span>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="space-around">
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <slot>
                <el-dropdown-item command="add">新增子部门</el-dropdown-item>
                <el-dropdown-item v-if="!isRoot" command="edit">编辑部门</el-dropdown-item>
                <el-dropdown-item v-if="!isRoot" command="del">删除部门</el-dropdown-item>
              </slot>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import { delDepartment } from '@/api/department'
export default {
  name: 'TreeTools',
  components: {

  },
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      //   required: true
      default: false
    }
  },
  data() {
    return {

    }
  },
  created() {

  },
  methods: {
    handleCommand(command) {
      if (command === 'add') {
        // 新增
        this.$emit('addDept', this.treeNode)
      } else if (command === 'edit') {
        this.$emit('editDept', this.treeNode)
        // 编辑
      } else if (command === 'del') {
        // 编辑
        // 通过elmecon
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async action => {
          console.log('删除')
          await delDepartment(this.treeNode.id)
          // 通过elme
          this.$message({
            message: '删除成功',
            type: 'success',
            showClose: true,
            duration: 3000
          })
          this.$emit('delDept')
        }).catch(() => {

        })
      }
    },
    handleDel() {
      console.log('删除')
    }
  }
}
</script>

<style lang="less" scoped>

</style>
